//
//  UIBarbuttonItem+Extension.swift
//  Weibo
//
//  Created by kobe on 2016/12/23.
//  Copyright © 2016年 kobe. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    
    /// 创建 UIBarButtonItem
    ///
    /// - parameter title:    title
    /// - parameter fontSize: fonSize 默认16
    /// - parameter target:   target
    /// - parameter action:   action
    /// - parameter isBack:   是否是返回按钮 如果是加上箭头
    ///
    /// - returns: UIBarButtonItem
    convenience init(title:String,fontSize:CGFloat = 16,target:AnyObject?, action:Selector,isBack:Bool = false) {
        let button:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
            button.setImage(UIImage(named:"navigationbar_back_withtext"), for: UIControlState(rawValue:0))
            button.setImage(UIImage(named:"navigationbar_back_withtext_highlighted"), for: .highlighted)
            button.sizeToFit()
        }
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView:button)
    }
    
}
